<template>
  <div class="app-container">
    <div class="head">
      <img src="@/assets/img/Layout/position.png" />
      <p class="see-block">配置列表</p>
    </div>
    <div class="view-container">
      <el-row :gutter="10" class="mb8" v-if="list.length == 0">
        <el-col :span="1.5">
          <el-button
            class="btn-success"
            type="primary"
            icon="el-icon-plus"
            size="mini"
            v-hasPermi="['system:sysK3cloudToConfigure:insert']"
            @click="handleAdd()"
          >新增</el-button>
        </el-col>
      </el-row>
      <el-row :gutter="10" class="mb8" v-if="list.length > 0">
        <el-col :span="22">
          <el-button 
            v-if="list[0].status !== '1'"
            class="btn-success"
            type="primary"
            size="mini"
            @click="handleData()"
          >数据同步</el-button>
        </el-col>
        <el-col :span="2" style="text-align:right;">
          <el-button size="mini" @click="getList">刷新</el-button>
        </el-col>
      </el-row>
      <el-table v-loading="loading" :data="list" border>
        <el-table-column label="序号" type="index" align="center" width="50">
          <template slot-scope="scope">
            <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column label="acctId"  align="center" prop="acctId" />
        <el-table-column label="appId"  align="center" prop="appId" />
        <el-table-column label="appSec"  align="center" prop="appSec" />
        <el-table-column label="userName"  align="center" prop="userName" />
        <el-table-column label="lcId"  align="center" prop="lcId" />
        <el-table-column label="serverUrl"  align="center" prop="serverUrl" />
        <el-table-column label="状态"  align="center" prop="status">
          <template slot-scope="scope">
            <div v-if="scope.row.status == 0" style="color:#13C2C2">未进行</div>
            <div v-if="scope.row.status == 1" style="color:#13C2C2">进行中</div>
            <div v-if="scope.row.status == 2" style="color:#52C41A">已完成</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click.native.stop="handleEdit(scope.row)"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              @click.native.stop="handleDetail(scope.row)"
            >详情</el-button>
            <el-button
              size="mini"
              type="text"
              v-hasPermi="['system:sysK3cloudToConfigure:deleteById']"
              @click.native.stop="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { k3cloudConfigList, k3cloudConfigDel, k3cloudConfigMaterialBasicDataSynchronization } from "@/api/system/k3cloudConfig/k3cloudConfig"
export default {
  name: "k3cloudConfig",
  data() {
    return {
      loading: true,
      total: 0,
      list: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.loading = true
      k3cloudConfigList(this.addDateRange(this.queryParams)).then(res => {
        this.list = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    // 新增
    handleAdd(){
      this.$router.push({path:"/k3cloudConfig/add"})
    },
    // 数据同步
    handleData(){
      let info = this.list[0]
      if(info && info.status !== '1'){
        this.getList()
        k3cloudConfigMaterialBasicDataSynchronization(info.id).then(res => {
          this.$modal.msgSuccess("数据同步中,请稍后查看！")
        })
      }else{
        this.$modal.msgError("数据同步中,请勿重复操作！")
      }
    },
    // 修改
    handleEdit(row){
      this.$router.push({path:"/k3cloudConfig/edit",query:{id: row.id}})
    },
    // 详情
    handleDetail(row){
      this.$router.push({path:"/k3cloudConfig/detail",query:{id: row.id}})
    },
    // 删除
    handleDelete(row){
      this.$modal.confirm('是否确认删除？').then(() => {
        k3cloudConfigDel(row.id).then((res) => {
          if(res.code == 200){
            this.getList()
            this.$modal.msgSuccess("删除成功！")
          }else{
            this.getList()
            this.$modal.msgError(res.msg)
          }
        })
      }).catch(() => {})
    },
  }
}
</script>